<template>
    <el-form ref="form" :model="form">
        <el-row>
            <el-col :span="6">
                <el-form-item label="学科" label-width="80px">
                    <el-select @change="hChangeSubject" v-model="form.subjectID" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in subjectList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="二级目录" label-width="80px">
                    <el-select v-model="form.catalogID" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in secDirectory"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="标签" label-width="80px">
                    <el-select v-model="form.tags" placeholder="请选择" style="width:100%">
                         <el-option
                            v-for="item in tagList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="关键词" label-width="80px">
                    <el-input v-model="form.keyword" placeholder="根据题干搜索"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="6">
                <el-form-item   label="试题类型" label-width="80px">
                    <el-select v-model="form.questionType" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in quesTypeList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="难度" label-width="80px">
                    <el-select v-model="form.difficulty" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in quesDiffcultyList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="方向" label-width="80px">
                    <el-select v-model="form.direction" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in directionList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="录入人" label-width="80px">
                    <el-select v-model="form.creatorID" placeholder="请选择" style="width:100%">
                        <el-option
                        v-for="item in enteredList"
                        :key="item.id"
                        :label="item.username"
                        :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="6">
                <el-form-item label="题目备注" label-width="80px">
                    <el-input v-model="form.remarks"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="企业简称" label-width="80px">
                    <el-input v-model="form.shortName"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="城市" label-width="80px">
                    <citys @input="getCitys" :value="city"></citys>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label-width="80px" style="text-align: right;">
                    <el-button @click="clearForm">清除</el-button>
                    <el-button type="primary" @click="getQuestionList">搜索</el-button>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
</template>
<script>
import citys from '../pages/companys/citys.vue'
import { simple } from '@/api/hmmm/subjects'
import { destorySimple } from '@/api/hmmm/directorys'
import { userSimple } from '@/api/base/users'
import { tagList } from '@/api/hmmm/tags'
export default {
  components: { citys },
  data () {
    return {
      quesTypeList: [
        { value: '1', label: '单选' },
        { value: '2', label: '多选' },
        { value: '3', label: '简答' }],
      quesDiffcultyList: [
        { value: '1', label: '简单' },
        { value: '2', label: '一般' },
        { value: '3', label: '困难' }],
      directionList: [
        { value: 'o2o', label: 'o2o' },
        { value: '外包服务', label: '外包服务' },
        { value: '企业服务', label: '企业服务' },
        { value: '互联网金融', label: '互联网金融' },
        { value: '企业咨询', label: '企业咨询' },
        { value: '互联网', label: '互联网' },
        { value: '电子商务', label: '电子商务' },
        { value: '其他', label: '其他' }
      ],
      subjectList: [], // 学科列表
      secDirectory: [], // 二级目录
      tagList: [], // 标签列表
      enteredList: [], // 录入人列表
      city: { city: '', province: '' },
      form: {}
    }
  },
  async created () {
    const subjectRes = await simple()
    this.subjectList = subjectRes.data
    // console.log(subjectRes.data)
    const enteredRes = await userSimple()
    this.enteredList = enteredRes.data
    // console.log(enteredRes)
  },
  methods: {
    clearForm () {
      this.form = {}
      this.city = { city: '', province: '' }
      this.$emit('cUpdateQuestion')
    },
    async getQuestionList () {
      const data = this.form
      this.$emit('update:updateQues', data)
      this.$emit('updateQues')
      //   console.log(data)
      this.$emit('update:updateChoice', data)
      this.$emit('updateChoice', data)
    },
    getCitys (value) {
      console.log(value)
      this.city = value
    },
    async hChangeSubject (value) {
      const destorySimpleRes = await destorySimple(value)
      this.secDirectory = destorySimpleRes.data
      const tagListRes = await tagList(value)
      this.tagList = tagListRes.data
    }
  }
}
</script>
